﻿using System;
using UnityEngine;
using System.Collections;

[System.Serializable]
public class EasyItem : IEquatable<EasyItem>, IComparable<EasyItem>
{

    public enum ItemType
    {
        random,
        regular
    }

    #region 变量
    [SerializeField]
    [Tooltip("物品")]
    private GameObject item;
    [SerializeField]
    [Tooltip("物品的长度，值为0不需要设置，会自动计算")]
    private float itemLength = 0;
    [SerializeField]
    [Tooltip("Y轴的偏移量")]
    private float offsetY = 0;
    [Tooltip("类型：随机生成型or规律生成型")]
    public ItemType itemType = ItemType.random;
    [SerializeField]
    [Tooltip("随机生成的几率,默认值为1，仅针对随机生成型")]
    private int probability = 1;
    [SerializeField]
    [Tooltip("规律生成间隔，每间隔几个生成一个规律体，仅针对规律生成型")]
    private int spawnInterval = 1;
    #endregion

    #region 属性
    public int SpawnInterval
    {
        get
        {
            if (spawnInterval <= 0)
            {
                return 1;
            }
            return spawnInterval + 1;
        }
    }
    public GameObject Item
    {
        get { return item; }
        set { item = value; }
    }
    public float ItemLength
    {
        get { return itemLength; }
        set { itemLength = value; }
    }
    public float OffsetY
    {
        get
        {
            return offsetY;
        }
    }
    public int Probability
    {
        get
        {
            if (probability <= 0)
            {
                return 1;
            }
            return probability;
        }
    }
    #endregion

    public bool Equals(EasyItem other)
    {
        if (other == null)
        {
            return false;
        }
        return this.SpawnInterval.Equals(other.SpawnInterval);
    }
    public int CompareTo(EasyItem other)
    {
        if (other == null)
        {
            return 1;
        }
        else
        {
            return -this.SpawnInterval.CompareTo(other.SpawnInterval);
        }

    }
}
